import Vue from "vue";
import VueRouter from "vue-router";
//import Home from "../views/Home.vue";
import Login from "@/views/common/Login.vue";
import Main from "@/views/Main.vue";

Vue.use(VueRouter);

//TODO:配置懒加载
/**
 * 组件加载方式，如果是开发环境，则不用懒加载，否则影响热更新
 * 如果是生产环境，则使用懒加载
 */
// const _import='';
// if(process.env.NODE_ENV==="production"){
//   _import=file => () => import('@/views/' + file + '.vue');
// }

// 全局路由，无需上下左右布局的嵌套
const globalRouters = [
  { path: "/", redirect: "/login" },
  {
    path: "/login",
    // component: Login
    component: Login
  }
];

//被导航栏、侧边栏包围的布局
const mainRouters = {
  path: "/home",
  component: Main

  // {
  //   path: "/",
  //   name: "Home",
  //   component: Home
  // },
  // {
  //   path: "/about",
  //   name: "About",
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () =>
  //     import(/* webpackChunkName: "about" */ "../views/About.vue")
  // }
};

const router = new VueRouter({
  mode: "hash",
  routes: globalRouters.concat(mainRouters)
});

export default router;
